<!doctype html>
<!--
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
  <meta charset="utf-8">
  <script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
  <script src="wct-browser-config.js"></script>
  <script src="../../node_modules/wct-browser-legacy/browser.js"></script>
</head>
<body>

<script type="module">
import { isAncestor, isDeep, isDescendant, root, matches, translate } from '../../lib/utils/path.js';
suite('path utilities', function() {

  test('root()', function() {
    assert.equal(root('foo'), 'foo');
    assert.equal(root('foo.bar'), 'foo');
  });

  test('isDeep()', function() {
    assert.equal(isDeep('foo'), false);
    assert.equal(isDeep('foo.bar'), true);
  });

  test('isAncestor()', function() {
    assert.equal(isAncestor('foo.bar', 'foo'),          true);

    assert.equal(isAncestor('foo.bar', 'foo.bar'),      false);
    assert.equal(isAncestor('foo.bar', 'foo.baz'),      false);
    assert.equal(isAncestor('foo.bar', 'fooz'),         false);
    assert.equal(isAncestor('foo.bar', 'bar'),          false);
    assert.equal(isAncestor('foo.bar', 'foo.bars'),     false);
    assert.equal(isAncestor('foo.bar', 'foo.bar.quux'), false);


    assert.equal(isAncestor('foo.bar.baz', 'foo'),      true);
    assert.equal(isAncestor('foo.bar.baz', 'foo.bar'),  true);

    assert.equal(isAncestor('foo.bar.baz', 'foo.baz'),  false);
    assert.equal(isAncestor('foo.bar.baz', 'foo.bars'), false);
  });

  test('isDescendant()', function() {
    assert.equal(isDescendant('foo.bar', 'foo.bar.baz'),  true);
    assert.equal(isDescendant('foo.bar', 'foo.bar'),      false);
    assert.equal(isDescendant('foo.bar', 'foo.bars'),     false);
    assert.equal(isDescendant('foo.bar', 'foo'),          false);
    assert.equal(isDescendant('foo.bar', 'bar'),          false);

    assert.equal(isDescendant('foo', 'foo.bar'), true);
    assert.equal(isDescendant('foo', 'foo'),     false);
  });

  test('translate()', function() {
    assert.equal(translate('foo', 'baz', 'foo.bar'),
                 'baz.bar');
    assert.equal(translate('foo', 'quux', 'foo.bar.baz'),
                 'quux.bar.baz');
    assert.equal(translate('foo.bar', 'quux', 'foo.bar.baz'),
                 'quux.baz');
  });

  test('matches()', function() {
    assert.equal(matches('foo.bar','foo'),          true);
    assert.equal(matches('foo.bar','foo.bar'),      true);
    assert.equal(matches('foo.bar','foo.bar.baz'),  true);
    assert.equal(matches('foo.bar','fooz'),         false);
    assert.equal(matches('foo.bar','foo.baz'),      false);
    assert.equal(matches('foo.bar','foo.bars'),     false);
  });
});
</script>
